package com.woniu.p2p.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.p2p.mapper.LoansMapper;
import com.woniu.p2p.mapper.UserMonloansMapper;
import com.woniu.p2p.service.MyrepayService;
import com.woniu.p2p.vo.MyrepayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MyrepayServiceImpl implements MyrepayService {

    @Autowired
    LoansMapper loansMapper;
    @Autowired
    UserMonloansMapper userMonloansMapper;

    @Override
    public PageInfo<MyrepayVo> findAllMyrepay(Integer id, Integer start) {
        PageHelper.startPage(start,100);
        List<MyrepayVo> allMyrepay = loansMapper.findAllMyrepay(id);
        for (MyrepayVo mv:allMyrepay
             ) {
            Integer loansId = mv.getLoansId();
            Long l1 = userMonloansMapper.findbalanceByUseridAndLoansId(id, loansId);
            long l = l1 == null ? 0 : l1;
            mv.setReleaseMoney(l);
            if(l!=0){
                mv.setStatus("未还清");
            }else {
                mv.setStatus("已还清");
            }
        }
        PageInfo<MyrepayVo> pageInfo=new PageInfo<>(allMyrepay);
        return pageInfo;
    }
}
